package com.example.cms.service.Impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.example.cms.entity.Customer;
import com.example.cms.pojo.FileExport;
import com.example.cms.pojo.Mesagge;
import com.example.cms.pojo.QueryPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.cms.dao.OrderDao;
import com.example.cms.entity.Order;
import com.example.cms.service.OrderService;

@Service("OrderService")
@Transactional
public class OrderServiceImpl implements OrderService{

	@Autowired
	private OrderDao orderDao;

	@Override
	public  List<Order> findOrdePage(Mesagge mesagge,QueryPage queryPage) {
		int i=orderDao.getOrdersNum();
		queryPage.setPageSize(4);
		mesagge.setMesCode(i);
		mesagge.setPageSize(queryPage.getPageSize());
		return orderDao.getAllOrders(queryPage);
	}

	/**
	 * @Author Sunbird
	 * @Description 查询所有订单信息
	 * @Date  2018/12/13
	 * @Param
	 * @return
	 **/
//	@Override
//	public List<Order> getAllorderS(Mesagge mesagge) {
//		int i=orderDao.getOrdersNum();
//		mesagge.setMesCode(i);//设置有多少条数
//		// TODO Auto-generated method stub
//		return orderDao.getAllOrders();
//	}

	@Override
	public Integer insertOrder(Order order) {
		return orderDao.insertOrder(order);
	}

	@Override
	public Integer deletOrder(int OrderId) {
		return orderDao.deleteOrder(OrderId);
	}

	@Override
	public Integer updateOrder(Order order) {
		return orderDao.updaeOrder(order);
	}

	@Override
	public FileExport exportUserDTO(QueryPage mesagge) throws Exception {
		//分页查询客户数据
		Mesagge p =new Mesagge();
		List<Order> oreder=orderDao.getAllOrdersById();
		//解析数据库数据 转换数据格式
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
		FileExport fileExport =new FileExport();
		List<FileExport> fileExports =new ArrayList<FileExport>();
		String [] state ={"未激活","激活"};
		//添加表名
		fileExport.setName("客户导出数据");
		//添加表头
		List<String> titles = new ArrayList();
		titles.add("客户名称");
		titles.add("订单编号");
		titles.add("订单名称");
		titles.add("订单数量");
		titles.add("订单时间");
		titles.add("订单金额");
		fileExport.setTitles(titles);
		//添加数据
		List<List<Object>> rows = new ArrayList();
		List<Object> c ;
		for (int i=0; i< oreder.size();i++){
			c=new ArrayList<Object>();
			c.add(oreder.get(i).getCustmoerName());
			c.add(oreder.get(i).getCustomerId());
			c.add(oreder.get(i).getOrderName());
			c.add(oreder.get(i).getOrderCout());
			c.add(oreder.get(i).getOrderDate());
			c.add(oreder.get(i).getOrderMoney());
			rows.add(c);
		}
		fileExport.setRows(rows);
		return fileExport;
	}	}


